package com.enhe.gck.fg;

import com.enhe.gck.communal.PublicMethod;
import com.enhe.gck.item.SupplyOrderHWANE16829Item;
import com.enhe.gck.pojo.Material;
import com.enhe.gck.pojo.Order;
import com.enhe.gck.pojo.SupplyOrder;
import com.enhe.gck.pojo.SupplyOrderBig;
import com.kuangkie.carbon.fg.*;
import com.kuangkie.carbon.fg.ops.FGOpsComplexus;
import com.kuangkie.carbon.fg.ops.ProRecordOps;
import com.kuangkie.carbon.panel.CarbonPanel;
import com.kuangkie.carbon.record.FGRecord;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Repository;
import com.kuangkie.carbon.record.FGRecordComplexus;
import com.kuangkie.carbon.record.ProRecord;
import com.enhe.gck.CarbonBaseConstant; //模型Code
import com.enhe.gck.CarbonEnumKeyValue; //枚举字典信息
import com.enhe.gck.CarbonRelationType; //关系类型Code
import com.enhe.gck.item.SupplyOrderBigHWANE18255Item; // 模型属性Code

import java.lang.reflect.Field;

@Repository(value = "hwane18255366042330866425862")
public class SupplyOrderBigHWANE18255BNB implements FirstRoundImproveFuncGroup,SecondRoundImproveFuncGroup, FetchFuncGroup {
	
	@Override
	public void secondImprove(FuncGroupContext context, ProRecord proRecord, FGRecordComplexus recordComplexus,
			ImproveResultFactory improveResultFactory) {
		SupplyOrderBig info=proRecord.getBean(SupplyOrderBig.class);
		if(proRecord.isNew()){
			OperationLogHWANE21797BNB.save(improveResultFactory,4,1,proRecord.getRecordCode());
			improveResultFactory.getCurrentProRecordOpsBuilder()
//					.putAttribute(SupplyOrderBigHWANE18255Item.基本属性组_单号,PublicMethod.getOrderCodeSMBig())
					.putAttribute(SupplyOrderBigHWANE18255Item.基本属性组_是否作废,false)
					.putAttribute(SupplyOrderBigHWANE18255Item.基本属性组_已供重量,0.0)
					.putAttribute(SupplyOrderBigHWANE18255Item.基本属性组_预计供重,0.0)
					;
		}else {
			if(info.getFlagCancel()!=null&&info.getFlagCancel()){
				SupplyOrderBig orderOld=CarbonPanel.getRecordDiscover(CarbonBaseConstant.供货计划_ghjh).getRecordBean(proRecord.getRecordCode(),SupplyOrderBig.class,1);
				if(orderOld!=null){
					if(info.getFlagCancel()!=null&&info.getFlagCancel()){
						if(!(orderOld.getFlagCancel()!=null&&orderOld.getFlagCancel())){
							OperationLogHWANE21797BNB.save(improveResultFactory,4,3,proRecord.getRecordCode());
						}
					}
				}
			}
		}
	}

	@Override
	public void fetchImprove(FuncGroupContext funcGroupContext, FGRecord fgRecord, FetchResultFactory fetchResultFactory) {
    }

	@Override
	public void preImprove(FuncGroupContext funcGroupContext, ProRecord proRecord, ProRecordOps proRecordOps, FGRecordComplexus fgRecordComplexus, FGOpsComplexus fgOpsComplexus, ImproveResultFactory improveResultFactory) {

	}

	@Override
	public void improve(FuncGroupContext funcGroupContext, ProRecord proRecord, FGRecordComplexus fgRecordComplexus, ImproveResultFactory improveResultFactory) {
		if(proRecord.isNew()){
			String materialId=proRecord.getGuestRecordCode(CarbonRelationType.RR_供货计划_原料_物料管理);
			if(materialId!=null){
				Material material=PublicMethod.getInfo(CarbonBaseConstant.物料管理_wlgl,materialId, Material.class);
				if(material!=null){
					improveResultFactory.getCurrentProRecordOpsBuilder().putAttribute(SupplyOrderBigHWANE18255Item.基本属性组_杂货,material.getIsGroceries());
				}
			}
		}
	}

	@Override
	public void postImprove(FuncGroupContext funcGroupContext, ProRecord proRecord, FGRecordComplexus fgRecordComplexus, ImproveResultFactory improveResultFactory) {

	}
}
